<template>
  <el-tabs v-model="current" v-if="loaded">
    <el-tab-pane label="基本信息" name="basic">
      <z-form :url="basicUrl" :closable="false" :data="partyData" :fields="basicFields">
      </z-form>
    </el-tab-pane>
    <el-tab-pane :disabled="isNew" label="发票信息" lazy name="invoice">
      <z-form url="/do/patch/party" :closable="false" :data="partyData" :fields="invoiceFields">
      </z-form>
    </el-tab-pane>
    <el-tab-pane :disabled="isNew" label="收款账户" lazy name="account">
      <z-form url="/do/patch/party" :closable="false" :data="partyData" lazy :fields="accountFields" />
    </el-tab-pane>
  </el-tabs>
</template>


<script>
import configs from "./.lowcode/configs";
export default {
  name: "p-j4k5c6p",
  provide: { configs },

  props: {
    params: null,
  },
  computed: {
    basicUrl() {
      return this.isNew ? "/do/put/party" : "/do/patch/party";
    },
  },
  data() {
    return {
      current: "basic",
      basicFields: [
        {
          name: "type",
          readonly: (formData) => !!formData.id,
          default: 1,
          onChange: (val) => {
            this.partyData.partType = val === 1 ? 2 : 1;
          },
        },
        {
          name: "partType",
          readonly: (formData) => !!formData.id || formData.type === 1,
          default: 2,
        },
        "title",
        {
          name: "uscc",
          visible: (formData) => formData.partType === 2,
        },
        {
          name: "idcard",
          visible: (formData) => formData.partType === 1,
        },
        "address",
        {
          name: "contactName",
          visible: (formData) => formData.partType === 2,
        },
        "telephone"
      ],
      invoiceFields: [
        "invoice",
        "mail"
      ],
      accountFields: [
        "account"
      ],
      loaded: false,
      isNew: true,
      partyData: {},
    };
  },
  async created() {
    const { id } = this.params;
    if (id) {
      await this.loadDetail(id);
    }
    this.loaded = true;
  },
  methods: {
    async loadDetail(id) {
      this.partyData = await $.get({ url: "/do/get/party", data: { id } });
      this.isNew = false;
    },
  }

};
</script>
